macos: add menu key equivalent option#12597
Closed
knu wants to merge 1 commit into
Closed
Conversation
Refs ghostty-org#12293 Related: ghostty-org#3493 (duplicates: ghostty-org#4374, ghostty-org#5091), ghostty-org#7013 Add `macos-menu-key-equivalents`, a macOS-specific setting for disabling menu key equivalents before they can intercept key events. It defaults to true, preserving existing menu behavior unless explicitly disabled. On macOS, AppKit evaluates menu key equivalents before Ghostty receives key events. This means a remap such as `key-remap = command=left_alt` still leaves `Command+N` captured by the New Window menu item before Ghostty can turn it into `Alt+N` for keybind and terminal input handling. Setting `macos-menu-key-equivalents` to false clears those menu shortcuts, so the key event reaches Ghostty instead of being consumed by AppKit. That allows Ghostty to apply `key-remap` first and dispatch the remapped key as terminal input or a Ghostty keybind. When disabled, this clears Ghostty-managed menu bindings and known standard macOS menu items, including dynamic items as their menus are opened. The original key equivalents are restored when the option is enabled again. Document the option and add Swift and Zig config coverage for it. AI usage: OpenAI Codex helped investigate, implement, test, and refine this change. I reviewed and tested the resulting code.
bo2themax
requested changes
May 6, 2026
Member
There was a problem hiding this comment.
This is still a workaround for the issue you mentioned. I believe the rc here is that pre-registered key bindings are not affected by key-remap, while Surface.keyEventIsBinding is using those mappings to query action, which will return null eventually and results in false in performKeyEquivalent.
But tbh, I'm not sure whether they should be remapped at all.
knu
added a commit
to knu/ghostty
that referenced
this pull request
May 6, 2026
Refs ghostty-org#12293 Related: ghostty-org#3493 (duplicates: ghostty-org#4374, ghostty-org#5091), ghostty-org#7013 Supersedes: ghostty-org#12597 Route key equivalent events with remapped modifiers through the normal key event path instead of dispatching the original physical shortcut through AppKit menus. This lets key-remap apply before Ghostty keybind lookup for shortcuts such as Cmd+N when command is remapped, while leaving non-remapped menu key equivalents on the existing AppKit path. Inspired by: @bo2themax (ghostty-org#12597 (review)) AI usage: OpenAI Codex helped investigate, implement, test, and refine this change. I reviewed and tested the resulting code.
Contributor
Author
|
@bo2themax Thanks, I agree this is better handled at the key event dispatch layer. I've just created #12602. |
knu
added a commit
to knu/ghostty
that referenced
this pull request
May 7, 2026
Refs ghostty-org#12293 Related: ghostty-org#3493 (duplicates: ghostty-org#4374, ghostty-org#5091), ghostty-org#7013 Supersedes: ghostty-org#12597 Apply `key-remap` before keybind lookup and when reporting keybind triggers for AppKit menu key equivalents. Previously, menu shortcuts were registered from the configured trigger without considering modifier remaps. This let AppKit consume the physical shortcut before Ghostty could match the remapped keybind. `Config.keyEventIsBinding` now remaps event modifiers before lookup, so remapped key equivalents match the same keybinds as normal key events. `CApi.config_trigger_` returns the physical trigger that maps back to the configured logical modifiers, and leaves triggers unset when no remapped physical shortcut can produce them. `RemapSet.unapply` performs the reverse lookup and is checked with `apply` so ambiguous or impossible remaps do not register incorrect menu shortcuts. Inspired by: @bo2themax (ghostty-org#12597 (review)) AI usage: OpenAI Codex helped investigate, implement, test, and refine this change. I reviewed and tested the resulting code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #12293
Related: #3493 (duplicates: #4374, #5091), #7013
Add
macos-menu-key-equivalents, a macOS-specific setting for disabling menu key equivalents before they can intercept key events. It defaults to true, preserving existing menu behavior unless explicitly disabled.On macOS, AppKit evaluates menu key equivalents before Ghostty receives key events. This means a remap such as
key-remap = command=left_altstill leavesCommand+Ncaptured by the New Window menu item before Ghostty can turn it intoAlt+Nfor keybind and terminal input handling.Setting
macos-menu-key-equivalentsto false clears those menu shortcuts, so the key event reaches Ghostty instead of being consumed by AppKit. That allows Ghostty to applykey-remapfirst and dispatch the remapped key as terminal input or a Ghostty keybind.When disabled, this clears Ghostty-managed menu bindings and known standard macOS menu items, including dynamic items as their menus are opened. The original key equivalents are restored when the option is enabled again.
Document the option and add Swift and Zig config coverage for it.
AI usage: OpenAI Codex helped investigate, implement, test, and refine this change. I reviewed and tested the resulting code.